<!DOCTYPE html>
<html lang="en">
<head prefix="og: http://ogp.me/ns#">
  <meta charset="utf-8">
  <title>starRTC文档</title>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Canonical links -->
  <link rel="canonical" href="https://starrtc.gitee.io/en/docs/web-4.html">
  <!-- Alternative links -->
  
    
      <link rel="alternative" hreflang="en" href="https://starrtc.gitee.io/docs/web-4.html">
    
      <link rel="alternative" hreflang="zh-cn" href="https://starrtc.gitee.io/zh-cn/docs/web-4.html">
    
  
  <!-- Icon -->
  <link rel="apple-touch-icon" sizes="57x57" href="/icon/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="114x114" href="/icon/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="72x72" href="/icon/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="144x144" href="/icon/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="60x60" href="/icon/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="120x120" href="/icon/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="76x76" href="/icon/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="152x152" href="/icon/apple-touch-icon-152x152.png">
  <link rel="icon" type="image/png" href="/icon/favicon-196x196.png" sizes="196x196">
  <link rel="icon" type="image/png" href="/icon/favicon-160x160.png" sizes="160x160">
  <link rel="icon" type="image/png" href="/icon/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="/icon/favicon-16x16.png" sizes="16x16">
  <link rel="icon" type="image/png" href="/icon/favicon-32x32.png" sizes="32x32">
  <meta name="msapplication-TileColor" content="#2f83cd">
  <meta name="msapplication-TileImage" content="/icon/mstile-144x144.png">
  <!-- CSS -->
  <!-- build:css build/css/navy.css -->
  <link rel="stylesheet" href="/css/navy.css">
  <!-- endbuild -->
  <link href="https://starrtc.gitee.io/googleapis.css" rel="stylesheet" type="text/css">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> 
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css">
  <!-- RSS -->
  <link rel="alternate" href="/atom.xml" title="starRTC文档">
  <!-- Open Graph -->
  <meta name="description" content="One-to-one messageIt takes ordinary text messages as an example in the document. If there are other data format requirements, the text can be replaced with the JSON data defined by yourself For exampl">
<meta property="og:type" content="website">
<meta property="og:title" content="starRTC文档">
<meta property="og:url" content="https://starrtc.gitee.io/en/docs/web-4.html">
<meta property="og:site_name" content="starRTC文档">
<meta property="og:description" content="One-to-one messageIt takes ordinary text messages as an example in the document. If there are other data format requirements, the text can be replaced with the JSON data defined by yourself For exampl">
<meta property="og:locale" content="en">
<meta property="og:updated_time" content="2020-09-06T00:27:31.352Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="starRTC文档">
<meta name="twitter:description" content="One-to-one messageIt takes ordinary text messages as an example in the document. If there are other data format requirements, the text can be replaced with the JSON data defined by yourself For exampl">
<meta name="twitter:site" content="hexojs">
<meta property="fb:admins" content="100000247608790">
  <!-- Google Analytics -->
  
</head>

<body>
  <div id="container">
    <header id="header" class="wrapper">
  <div id="header-inner" class="inner">
    <h1 id="logo-wrap">
      
      <a href="https://starrtc.gitee.io/" id="logo">starRTC</a>
    </h1>
    <nav id="main-nav">
      <a href="https://starrtc.gitee.io/" class="main-nav-link">Home</a><a href="https://blog.starRTC.com" class="main-nav-link">Blog</a><a href="https://github.com/starrtc/android-demo/issues" class="main-nav-link">Forum</a><a href="/en/docs/" class="main-nav-link">Docs</a><a href="/en/download/" class="main-nav-link">Download</a><a href="/en/contact/" class="main-nav-link">Contact</a>
      
    </nav>
    <div id="lang-select-wrap">
      <label id="lang-select-label"><i class="fa fa-globe"></i><span>English</span></label>
      <select id="lang-select" data-canonical="docs/web-4.html">
        
          <option value="en" selected>English</option>
        
          <option value="zh-cn">简体中文</option>
        
      </select>
    </div>
    <a id="mobile-nav-toggle">
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
    </a>
  </div>
</header>

    <div id="content-wrap">
  <div id="content" class="wrapper">
    <div id="content-inner">
      <article class="article-container" itemscope itemtype="http://schema.org/Article">
        <div class="article-inner">
          <div class="article">
            <div class="inner">
              <header class="article-header">
                <h1 class="article-title" itemprop="name"></h1>
                <a href="https://github.com/starRTC/docs/edit/master/en/docs/web-4.md" class="article-edit-link" title="Improve this doc"><i class="fa fa-pencil"></i></a>
              </header>
              <div class="article-content" itemprop="articleBody">
                <h1 id="One-to-one-message" class="article-heading"><a href="#One-to-one-message" class="headerlink" title="One-to-one message"></a>One-to-one message<a class="article-anchor" href="#One-to-one-message" aria-hidden="true"></a></h1><p>It takes ordinary text messages as an example in the document. If there are other data format requirements, the text can be replaced with the JSON data defined by yourself</p>
<p>For example, if you want to send a picture, you can upload it to your own server or use a 3rd party image storage (such as Qi Niuyun, Alibaba Cloud OSS, etc.) to upload the image and send the URL.。</p>
<h2 id="4-1-Receiving-one-to-one-messages" class="article-heading"><a href="#4-1-Receiving-one-to-one-messages" class="headerlink" title="4.1 Receiving one-to-one messages"></a>4.1 Receiving one-to-one messages<a class="article-anchor" href="#4-1-Receiving-one-to-one-messages" aria-hidden="true"></a></h2><p>Receiving the one-to-one message through a callback function passed in during the login process;<br><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">callBack</span>(<span class="params">data,status</span>) </span>&#123;</span><br><span class="line">	<span class="keyword">switch</span> (status)&#123;</span><br><span class="line">		...</span><br><span class="line">		<span class="keyword">case</span> <span class="string">"onVoipMessage"</span>:</span><br><span class="line">			<span class="comment">//Received the voip message</span></span><br><span class="line">			<span class="keyword">switch</span>(data.type)</span><br><span class="line">			&#123;	</span><br><span class="line">				<span class="keyword">case</span> <span class="string">"voipCall"</span>:</span><br><span class="line">				<span class="comment">//Received a voip call message</span></span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">				<span class="keyword">case</span> <span class="string">"voipRefuse"</span>:</span><br><span class="line">				<span class="comment">//Received a voip rejection message</span></span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">				</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">"onSingleMessage"</span>:</span><br><span class="line">			<span class="comment">//data结构</span></span><br><span class="line">			<span class="comment">//data = &#123;</span></span><br><span class="line">			<span class="comment">//	"fromId": message source</span></span><br><span class="line">			<span class="comment">//	"digest":</span></span><br><span class="line">			<span class="comment">//	"msg": Message structure</span></span><br><span class="line">			<span class="comment">//&#125;</span></span><br><span class="line">			<span class="comment">//msg structure</span></span><br><span class="line">			<span class="comment">//msg = &#123;</span></span><br><span class="line">			<span class="comment">//	"fromId":  Message source</span></span><br><span class="line">			<span class="comment">//	"targetId": Message receiver</span></span><br><span class="line">			<span class="comment">//	"time": Timestamp</span></span><br><span class="line">			<span class="comment">//	"msgIndex": Message sequence number</span></span><br><span class="line">			<span class="comment">//	"type": type</span></span><br><span class="line">			<span class="comment">//	"code": Message control type code</span></span><br><span class="line">			<span class="comment">//	"contentData": Message content</span></span><br><span class="line">			<span class="comment">//&#125;;</span></span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//Login to the SDK</span></span><br><span class="line"><span class="keyword">var</span> starSDK = <span class="keyword">new</span> StarRtc.StarSDK();</span><br><span class="line">starSDK.login(appID,userId,authKey,callBack);</span><br></pre></td></tr></table></figure></p>
<h2 id="4-2-Send-one-to-one-messages" class="article-heading"><a href="#4-2-Send-one-to-one-messages" class="headerlink" title="4.2 Send one-to-one messages"></a>4.2 Send one-to-one messages<a class="article-anchor" href="#4-2-Send-one-to-one-messages" aria-hidden="true"></a></h2><p>The messages are divided into ordinary message(sendMessage) and online message(sendOnLineMessage).</p>
<p>“Normal message” refers to a normal chat message, which is cached when the user is offline, and it will be took all offline messages when they go online again.</p>
<p>“Online messages” are only received when the receiver is online, which are not cached.</p>
<p>Example:<br><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Send one-to-one messages</span></span><br><span class="line"><span class="comment"> * @param _targetId 	target userId</span></span><br><span class="line"><span class="comment"> * @param _digest 		digest</span></span><br><span class="line"><span class="comment"> * @param _txt 			text</span></span><br><span class="line"><span class="comment"> * @param _type 		message type</span></span><br><span class="line"><span class="comment"> */</span>	</span><br><span class="line">StarRtc.StarSDK.sendSingleMsg(_targetId,_digest,_txt, _type);</span><br></pre></td></tr></table></figure></p>

              </div>
              <footer class="article-footer">
                <time class="article-footer-updated" datetime="2020-09-06T00:27:31.352Z" itemprop="dateModified">Last updated<script type="text/javascript">document.write("："+(new Date()).toISOString().slice(0,10))</script></time>
		<a href="web-2.html" class="article-footer-prev" title="2.SDK intro"><i class="fa fa-chevron-left"></i><span>Prev</span></a><a href="web-5.html" class="article-footer-next" title="5.group msg"><span>Next</span><i class="fa fa-chevron-right"></i></a>
              </footer>
            </div>
          </div>
          <aside id="article-toc" role="navigation">
            <div id="article-toc-inner">
              <strong class="sidebar-title">Contents</strong>
              <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#One-to-one-message"><span class="toc-text">One-to-one message</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#4-1-Receiving-one-to-one-messages"><span class="toc-text">4.1 Receiving one-to-one messages</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-2-Send-one-to-one-messages"><span class="toc-text">4.2 Send one-to-one messages</span></a></li></ol></li></ol>
              <a href="#" id="article-toc-top">Back to Top</a>
            </div>
          </aside>
        </div>
      </article>
      <aside id="sidebar" role="navigation">
  <div class="inner">
    <strong class="sidebar-title">Getting Started</strong><a href="index.html" class="sidebar-link">Overview</a><strong class="sidebar-title">Android</strong><a href="android-1.html" class="sidebar-link">1.prerequisite</a><a href="android-2.html" class="sidebar-link">2.SDK intro</a><a href="android-3b.html" class="sidebar-link">3b.init(private)</a><a href="android-4.html" class="sidebar-link">4.im</a><a href="android-5.html" class="sidebar-link">5.group msg</a><a href="android-6.html" class="sidebar-link">6.chatroom msg</a><a href="android-7.html" class="sidebar-link">7.voip</a><a href="android-8.html" class="sidebar-link">8.meeting</a><a href="android-9.html" class="sidebar-link">9.live</a><a href="android-10.html" class="sidebar-link">10.other components</a><a href="android-11.html" class="sidebar-link">11.super room</a><a href="android-user-list.html" class="sidebar-link">online user list</a><a href="android-beauty-callback.html" class="sidebar-link">beauty</a><a href="android-errCode.html" class="sidebar-link">ErrorCode</a><strong class="sidebar-title">iOS</strong><a href="ios-1.html" class="sidebar-link">1.prerequisite</a><a href="ios-2.html" class="sidebar-link">2.SDK intro</a><a href="ios-3b.html" class="sidebar-link">3b.init(private)</a><a href="ios-4.html" class="sidebar-link">4.im</a><a href="ios-5.html" class="sidebar-link">5.group msg</a><a href="ios-6.html" class="sidebar-link">6.chatroom msg</a><a href="ios-7.html" class="sidebar-link">7.voip</a><a href="ios-8.html" class="sidebar-link">8.meeting</a><a href="ios-9.html" class="sidebar-link">9.live</a><a href="ios-10.html" class="sidebar-link">10.voip direct connection</a><strong class="sidebar-title">web</strong><a href="web-1.html" class="sidebar-link">1.prerequisite</a><a href="web-2.html" class="sidebar-link">2.SDK intro</a><a href="web-4.html" class="sidebar-link current">4.im</a><a href="web-5.html" class="sidebar-link">5.group msg</a><a href="web-6.html" class="sidebar-link">6.chatroom msg</a><a href="web-7.html" class="sidebar-link">7.voip</a><a href="web-8.html" class="sidebar-link">8.meeting</a><a href="web-9.html" class="sidebar-link">9.live</a><a href="web-10.html" class="sidebar-link">10.private</a><strong class="sidebar-title">Win PC</strong><a href="win-1.html" class="sidebar-link">1.prerequisite</a><a href="win-2.html" class="sidebar-link">2.init</a><a href="win-3.html" class="sidebar-link">3.im</a><a href="win-4.html" class="sidebar-link">4.group msg</a><a href="win-5.html" class="sidebar-link">5.chatroom msg</a><a href="win-6.html" class="sidebar-link">6.voip</a><a href="win-7.html" class="sidebar-link">7.meeting</a><a href="win-8.html" class="sidebar-link">8.live</a><strong class="sidebar-title">Server API</strong><a href="aec-index.html" class="sidebar-link">Overview</a><a href="aec-group.html" class="sidebar-link">group events</a><a href="aec-chatroom.html" class="sidebar-link">chatroom events</a><a href="aec-voip.html" class="sidebar-link">voip events</a><a href="aec-channel.html" class="sidebar-link">音视频流事件通知</a><a href="aec-other.html" class="sidebar-link">other events</a>
  </div>
</aside>
    </div>
  </div>
</div>

    <footer id="footer" class="wrapper">
  <div class="inner">
    <div id="footer-copyright">
      &copy; 2010-2020 <a href="https://starrtc.gitee.io/" target="_blank">starRTC</a><br>
    </div>
    <div id="footer-links">
      <a href="https://gitee.com/starrtc" class="footer-link" target="_blank"><i class="fa fa-github-alt"></i></a>
    </div>
  </div>
</footer>

  </div>
  <div id="mobile-nav-dimmer"></div>
  <nav id="mobile-nav">
  <div id="mobile-nav-inner">
    <ul id="mobile-nav-list">
      <a href="https://starrtc.gitee.io/" class="main-nav-link">Home</a><a href="https://blog.starRTC.com" class="main-nav-link">Blog</a><a href="https://github.com/starrtc/android-demo/issues" class="main-nav-link">Forum</a><a href="/en/docs/" class="mobile-nav-link">Docs</a><a href="/en/download/" class="mobile-nav-link">Download</a><a href="/en/contact/" class="mobile-nav-link">Contact</a>
      <li class="mobile-nav-item">
        <a href="https://github.com/starrtc" class="mobile-nav-link" rel="external" target="_blank">GitHub</a>
      </li>
    </ul>
    
      <strong class="mobile-nav-title">Getting Started</strong><a href="index.html" class="mobile-nav-link">Overview</a><strong class="mobile-nav-title">Android</strong><a href="android-1.html" class="mobile-nav-link">1.prerequisite</a><a href="android-2.html" class="mobile-nav-link">2.SDK intro</a><a href="android-3b.html" class="mobile-nav-link">3b.init(private)</a><a href="android-4.html" class="mobile-nav-link">4.im</a><a href="android-5.html" class="mobile-nav-link">5.group msg</a><a href="android-6.html" class="mobile-nav-link">6.chatroom msg</a><a href="android-7.html" class="mobile-nav-link">7.voip</a><a href="android-8.html" class="mobile-nav-link">8.meeting</a><a href="android-9.html" class="mobile-nav-link">9.live</a><a href="android-10.html" class="mobile-nav-link">10.other components</a><a href="android-11.html" class="mobile-nav-link">11.super room</a><a href="android-user-list.html" class="mobile-nav-link">online user list</a><a href="android-beauty-callback.html" class="mobile-nav-link">beauty</a><a href="android-errCode.html" class="mobile-nav-link">ErrorCode</a><strong class="mobile-nav-title">iOS</strong><a href="ios-1.html" class="mobile-nav-link">1.prerequisite</a><a href="ios-2.html" class="mobile-nav-link">2.SDK intro</a><a href="ios-3b.html" class="mobile-nav-link">3b.init(private)</a><a href="ios-4.html" class="mobile-nav-link">4.im</a><a href="ios-5.html" class="mobile-nav-link">5.group msg</a><a href="ios-6.html" class="mobile-nav-link">6.chatroom msg</a><a href="ios-7.html" class="mobile-nav-link">7.voip</a><a href="ios-8.html" class="mobile-nav-link">8.meeting</a><a href="ios-9.html" class="mobile-nav-link">9.live</a><a href="ios-10.html" class="mobile-nav-link">10.voip direct connection</a><strong class="mobile-nav-title">web</strong><a href="web-1.html" class="mobile-nav-link">1.prerequisite</a><a href="web-2.html" class="mobile-nav-link">2.SDK intro</a><a href="web-4.html" class="mobile-nav-link current">4.im</a><a href="web-5.html" class="mobile-nav-link">5.group msg</a><a href="web-6.html" class="mobile-nav-link">6.chatroom msg</a><a href="web-7.html" class="mobile-nav-link">7.voip</a><a href="web-8.html" class="mobile-nav-link">8.meeting</a><a href="web-9.html" class="mobile-nav-link">9.live</a><a href="web-10.html" class="mobile-nav-link">10.private</a><strong class="mobile-nav-title">Win PC</strong><a href="win-1.html" class="mobile-nav-link">1.prerequisite</a><a href="win-2.html" class="mobile-nav-link">2.init</a><a href="win-3.html" class="mobile-nav-link">3.im</a><a href="win-4.html" class="mobile-nav-link">4.group msg</a><a href="win-5.html" class="mobile-nav-link">5.chatroom msg</a><a href="win-6.html" class="mobile-nav-link">6.voip</a><a href="win-7.html" class="mobile-nav-link">7.meeting</a><a href="win-8.html" class="mobile-nav-link">8.live</a><strong class="mobile-nav-title">Server API</strong><a href="aec-index.html" class="mobile-nav-link">Overview</a><a href="aec-group.html" class="mobile-nav-link">group events</a><a href="aec-chatroom.html" class="mobile-nav-link">chatroom events</a><a href="aec-voip.html" class="mobile-nav-link">voip events</a><a href="aec-channel.html" class="mobile-nav-link">音视频流事件通知</a><a href="aec-other.html" class="mobile-nav-link">other events</a>
    
  </div>
  <div id="mobile-lang-select-wrap">
    <span id="mobile-lang-select-label"><i class="fa fa-globe"></i><span>English</span></span>
    <select id="mobile-lang-select" data-canonical="docs/web-4.html">
      
        <option value="en" selected>English</option>
      
        <option value="zh-cn">简体中文</option>
      
    </select>
  </div>
</nav>
  <!-- Scripts -->
<!-- build:js build/js/main.js -->
<script src="/js/lang_select.js"></script>
<script src="/js/toc.js"></script>
<script src="/js/mobile_nav.js"></script>
<!-- endbuild -->
<!-- Algolia -->

<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
<script type="text/javascript">
document.getElementById('search-input-wrap').classList.add('on');
docsearch({
  apiKey: 'c3d5d4c995b5e0c2ffb5623900279a66',
  indexName: 'hexo',
  inputSelector: '#search-input'
});
</script>


</body>
</html>